Concept operators

Description

Concept provides a series of operators, including the operators found in C++. The operators precedence is the same as in C.

When boolean is requested various data types evaluate like this:
        numbers        null or 0 is false, non-zero is true
        strings                an empty string is false, a string with at least one character is true
        arrays                an array containing no elements is false, at least one element is true
        objects                always true
        delegates        always true

        

Unary operators
new        (new operator)
        Applies to:        classes
delete        (delete operator)
        Applies to:        objects and arrays
        * Note that delete frees the current variable. If other variables point to the same object or array, those will not be freed (that is the garbage collector's job)
typeof        (type operator)
        Applies to:        numbers, strings, arrays, objects and delegates
        * Returns a string containing the variable type, respectively "numeric", "string", "array", "class" and "delegate"
classof        (class name operator)
        Applies to:        numbers, strings, arrays, objects and delegates but is intended to be used only by objects.
        * Returns the class name of the current object as a string or an empty string if the variable/expression is not an object.
length        (length operator)
        Applies to:        strings and arrays
        * Returns the character count for strings and the element count for arrays.
value        (length operator)
        Applies to:        strings
        * Evaluates the string to a number and returns it

!        (negation)
        Applies to:        numbers, strings, arrays, objects and delegates
~         (complement)
        Applies to:        numbers
++        (left increment)
        Applies to:        numbers, strings
--        (left decrement)
        Applies to:        numbers
++        (right increment)
        Applies to:        numbers, strings
--        (right increment)
        Applies to:        numbers



Binary operators

Multiplicative:
/        (division)
        Applies to:        numbers
%        (reminder)
        Applies to:        numbers
*        (multiplicative)
        Applies to:        numbers

Additive
+        (sum)
        Applies to:        numbers, strings, arrays
-        (difference)
        Applies to:        numbers

Shifting
<<        (shift left)
        Applies to:        numbers
>>        (shift right)
        Applies to:        numbers


Comparison
<        (less)
        Applies to:        numbers, strings
<=        (less or equal)
        Applies to:        numbers, strings
>        (greater)
        Applies to:        numbers, strings
>=        (greater or equal)
        Applies to:        numbers, strings
==        (equal)
        Applies to:        numbers, strings, arrays, objects and delegates
!=        (different)
        Applies to:        numbers, strings, arrays, objects and delegates

Bitwise
&        (bitwise and)
        Applies to:        numbers
^        (bitwise exclusive or)
        Applies to:        numbers
|        (bitwise inclusive or)
        Applies to:        numbers

Logical
&&        (logical and)
        Applies to:        numbers, strings, arrays, objects and delegates
||        (logical or)
        Applies to:        numbers, strings, arrays, objects and delegates


Assignment
=        (assignment)
        Applies to:        numbers, strings, arrays, objects and delegates
=&        (forced assignment)
        Applies to:        numbers, strings, arrays, objects and delegates
        * Behaves exactly the same as = except when used on a object of a class that overloads the = operator. Its an assignment operator that cannot be overloaded.

+=        (increment)
        Applies to:        numbers, strings and arrays
-=        (subtract)
        Applies to:        numbers
/=        (divide with)
        Applies to:        numbers
%=        (remainder of the divide with)
        Applies to:        numbers
*=        (multiply by)
        Applies to:        numbers
&=        (bitwise and with)
        Applies to:        numbers
^=        (bitwise exclusive or with)
        Applies to:        numbers
|=        (bitwise inclusive or with)
        Applies to:        numbers
<<=        (shift left by)
        Applies to:        numbers
>>=        (shift right by)
        Applies to:        numbers

::        (static selector)
        Applies to:        classes
[]        (index selector)
        Applies to:        arrays and strings
. or ->        (object selector)
        Applies to:        objects.


A class can overload the following operators:
*, /, %, +, -, <<, >>, <, <=, >, >=, ==, !=, &, ^, |, &&, ||, =, +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=, [], !, ~, ++(at left), --(at left)

The [] operator is the only operator that returns a reference to the given variable or expression.

An operator can be overloaded as in the example bellow.

Example
class X {
	// for binary operators
	operator +(a) {
		return a+10;
	}

	// for unary operators
	operator !() {
		return false;
	}

	var x;
	operator [](index) {
		return x; // will return a reference to x. 
	}
}